﻿using System;
using GNUGo.Net.WebApp.Entities;

namespace GNUGo.Net.WebApp.WsClasses {
	[Serializable]
	public class WsGame {
		public WsGame() { }

		public WsGame(GoGame goGame, GoPlayer blackPlayer, GoPlayer whitePlayer, int currentPlayerId) {
			GameId = goGame.GameId;

			// the opponent is black if the currently logged in user is white
			OpponentIsBlack = currentPlayerId == whitePlayer.PlayerId;

			GoPlayer opponent = OpponentIsBlack ? blackPlayer : whitePlayer;
			Opponent = new WsPlayer(opponent);

			BoardSize = goGame.BoardSize;
			BlackHandicap = goGame.BlackHandicap;
			Komi = goGame.Komi;
			DateRequestAccepted = goGame.DateRequestAccepted;
			Rated = goGame.Rated;
			RequestInitiatedByBlack = goGame.RequestInitiatedByBlack;
			CurrentMoveNumber = goGame.CurrentMoveNumber;
			DateOpponentAcceptedDeadStones = OpponentIsBlack
			                                 	? goGame.DateBlackAcceptedDeadGroups
			                                 	: goGame.DateWhiteAcceptedDeadGroups;
			DateCurrentUserAcceptedDeadStones = OpponentIsBlack
			                                    	? goGame.DateWhiteAcceptedDeadGroups
			                                    	: goGame.DateBlackAcceptedDeadGroups;
		}

		public WsGame(GoGame goGame, int currentPlayerId) : this(
				goGame, 
				goGame.GoPlayerBlack, 
				goGame.GoPlayerWhite, 
				currentPlayerId
				) {

		}

		public int GameId { get; set; }
		public WsPlayer Opponent { get; set; }
		public bool OpponentIsBlack { get; set; }
		public int BoardSize { get; set; }
		public int BlackHandicap { get; set; }
		public decimal Komi { get; set; }
		public DateTime? DateRequestAccepted { get; set; }
		public DateTime? DateOpponentAcceptedDeadStones { get; set; }
		public DateTime? DateCurrentUserAcceptedDeadStones { get; set; }
		public bool Rated { get; set; }
		public bool RequestInitiatedByBlack { get; set; }
		public int CurrentMoveNumber { get; set; }
	}
}
